using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DevelopEngine;
using System;

namespace xingzhimeng
{
  ///<summary>
  ///
  ///</summary>
  ///
  public class CustomsData
    {
        public const string customs1 = "Customs1";//关卡解锁个数
        public const string customs2 = "Customs2";//关卡解锁个数
        public const string customs3 = "Customs3";//关卡解锁个数
        public const string StarCount = "StarCount";//星星总数
        //各关卡星星数储存命名格式 lever+关卡名    (1_1);
       

    }
public class CustomsManager : MonoBehaviour
{
        public List<GameObject> sons;//关卡对象
        
        [Tooltip("章节名称")]
        public string CustomName;
        private void Awake()
        {

         //   PlayerPrefs.SetInt(CustomName, 0);
         //   PlayerPrefs.SetInt(CustomsData.StarCount, 0);
         //   PlayerPrefs.SetInt("1_1", 0);
         //   PlayerPrefs.SetInt("1_2", 0);

            sons = new List<GameObject>();
            for(int i = 0; i < transform.childCount; i++)
            {
                sons.Add(transform.GetChild(i).gameObject);
            }
            
            

        }
        //刷新UI
        public void Init()
        {
            int index = PlayerPrefs.GetInt(CustomName,0);
          //  print(index);
          //  print(PlayerPrefs.GetInt(CustomsData.StarCount));
          //  print(PlayerPrefs.GetInt("1_1"));
          //  print(PlayerPrefs.GetInt("1_2"));
            if (index >= sons.Count) return;
            //Customs1
            string cust = CustomName.Substring(7);
            for(int i = 0; i < index+1; i++)
            {
                //关卡解锁时的操作
                sons[i].GetComponent<BoxCollider>().enabled = true;
                sons[i].GetComponent<Button>().enabled = true;
              //  sons[i].transform.Find("Text").gameObject.SetActive(true);
                sons[i].transform.Find("Lock").gameObject.SetActive(false);//关闭锁
                if (i < index)
                {
                    //激活关卡星星
                    int star = PlayerPrefs.GetInt(cust + "_" + (i + 1));
                    if (star > 0 && star <= 3)
                    {
                        sons[i].transform.Find("Star" + star).gameObject.SetActive(true);
                    }
                }
            }

        }
        public void ToCusoms(string sceneName)
        {
            SceneManagle1.Instance.GoTarget(sceneName);
        }
        //切换游戏场景
       
    }

}

